package managedbean;

import entity.CustomerEntity;
import entity.FnBBranchEntity;
import entity.FnBProductEntity;
import entity.FnBReservationEntity;
import entity.FoodTypeEntity;
import entity.MealEntity;
import entity.ProductEntity;
import entity.ReservationEntity;
import entity.SetMealEntity;
import entity.TableTypeEntity;
import java.io.IOException;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.PhaseEvent;
import javax.faces.model.SelectItem;
import org.primefaces.event.SelectEvent;
import session.stateful.ProductSessionBean;
import session.stateful.ReservationSessionBean;

@ManagedBean
@SessionScoped
public class ReservationManagerBean {

    @EJB
    private ReservationSessionBean reservationSessionBean;
    @EJB
    private ProductSessionBean productSessionBean;
    private CustomerEntity customer;
    private List<ProductEntity> listOfProduct;
    private List<List<FnBProductEntity>> listOfCategory;
    private List<FoodTypeEntity> listOfFoodType;
    private FnBProductEntity[] selectedProduct;
    private List<List<FnBProductEntity>> choiceList;
    private Map<Long, Double> priceList;
    private Map<Long, Integer> quantityList;
    private boolean reloadPage;
    private Map<String, Integer> foodMap;
    private FnBProductEntity meal;
    private int quantity;
    private double totalBill;
    private double discountBill;
    private FnBReservationEntity reservation;
    private long branchId;
    private List<TableTypeEntity> tableList;
    //to store the available tables of each table type
    //for visitor to select
    private int[] quantityAvail;
    private boolean reloadTable = true;
    private int[][][] capacity;
    int interval;
    private List<SelectItem> availSlot;
    //to test the table retrieval. Delete later
    private int test;
    private int timeInput;
    private int[] selectedQuantity;
    private List testList;
    private int count = 0;
    private int count1 = 0;
    private int count2 = 0;
    private int index = 0;
    private Integer testClass;
    private List<TableTypeEntity> selectedTable;
    private List<Integer> selectedTableQuantity;
    private boolean finish;
    private int numOfType;
    private FnBReservationEntity[] selectedReservations_status;
    private FnBReservationEntity[] selectedReservations_confirm;
    private FnBReservationEntity selectedReservation;
    private List<FnBReservationEntity> fandBs;
    private List<FnBReservationEntity> fandBShow;
    private List<FnBReservationEntity> fandBNoShow;
    private List<FnBReservationEntity> fandBConfirmed;
    private List<FnBReservationEntity> fandBRejected;
    private List<FnBReservationEntity> allFandB;
    private List<FnBReservationEntity> pendingConfirmations;
    private Date date;
    private String option;
    private List<String> options = new ArrayList<String>();
    private FnBBranchEntity selectedBranch;
    private boolean createTable = false;

    public List<FnBReservationEntity> getPendingConfirmations() {
        pendingConfirmations = new ArrayList<FnBReservationEntity>();
        List<ReservationEntity> tempList = reservationSessionBean.getReservationListByBranchId(selectedBranch.getId());
        for (Object obj : tempList) {
            if (obj instanceof FnBReservationEntity) {
                FnBReservationEntity temp = (FnBReservationEntity) obj;
                if (temp.getConfirmation().equalsIgnoreCase("Pending")) {
                    pendingConfirmations.add(temp);
                }
            }
        }
        setOptions(new ArrayList<String>());
        getOptions().add("Confirm");
        getOptions().add("Reject");
        return pendingConfirmations;
    }

    public void initViewPendingConfirmation(PhaseEvent event) {
        selectedBranch = (FnBBranchEntity) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("selectedBranch");
    }

    public List<FnBReservationEntity> getAllFandB() {
        allFandB = new ArrayList<FnBReservationEntity>();
        selectedBranch = (FnBBranchEntity) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("selectedBranch");
        List<ReservationEntity> tempList = reservationSessionBean.getReservationListByBranchId(selectedBranch.getId());
        for (Object obj : tempList) {
            if (obj instanceof FnBReservationEntity) {
                FnBReservationEntity temp = (FnBReservationEntity) obj;
                allFandB.add(temp);
            }
        }
        return allFandB;
    }

    public void initUpdateCustomerStatus(PhaseEvent event) {
    }

    public void fandBListActionListener(ActionEvent event) throws IOException {
        selectedBranch = (FnBBranchEntity) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("selectedBranch");
        getFandBList();
    }

    public void getFandBList() throws IOException {
        fandBs = new ArrayList<FnBReservationEntity>();
        List<ReservationEntity> tempList = reservationSessionBean.getReservationListByBranchId(selectedBranch.getId());
        for (Object obj : tempList) {
            if (obj instanceof FnBReservationEntity) {
                FnBReservationEntity temp = (FnBReservationEntity) obj;
                if ((temp.getDateReserved().compareTo(getDate()) <= 0) && (temp.getCustomerStatus().equalsIgnoreCase("Pending")) && temp.getConfirmation().equalsIgnoreCase("Confirmed")) {
                    fandBs.add((FnBReservationEntity) obj);
                }
            }
        }
        FacesContext.getCurrentInstance().getExternalContext().redirect("StakeholderUpdateCustomerStatus.xhtml");
    }

    public void updateStatus(ActionEvent event) throws IOException {
        fandBShow = new ArrayList<FnBReservationEntity>();
        fandBNoShow = new ArrayList<FnBReservationEntity>();
        for (int i = 0; i < selectedReservations_status.length; i++) {
            FnBReservationEntity temp = selectedReservations_status[i];
            if (temp != null) {
                reservationSessionBean.toShow(temp.getId());
                fandBs.remove(temp);
                temp.setCustomerStatus("Show");
                fandBShow.add(temp);
            }
        }
        for (Object o : fandBs) {
            FnBReservationEntity temp = (FnBReservationEntity) o;
            reservationSessionBean.toNoShow(temp.getId());
            temp.setCustomerStatus("No Show");
            fandBNoShow.add(temp);
        }
        FacesContext.getCurrentInstance().getExternalContext().redirect("StakeholderViewCustomerStatusUpdateResult.xhtml");
    }

    public void toConfirmed(ActionEvent event) throws IOException {

        fandBConfirmed = new ArrayList<FnBReservationEntity>();

        for (Object o : selectedReservations_confirm) {
            FnBReservationEntity temp = (FnBReservationEntity) o;

            reservationSessionBean.toConfirmed(temp.getId());
            temp.setConfirmation("Confirmed");
            getFandBConfirmed().add(temp);

        }
        FacesContext.getCurrentInstance().getExternalContext().redirect("StakeholderViewConfirmationUpdateResult.xhtml");
    }

    public void toRejected(ActionEvent event) throws IOException {
        fandBRejected = new ArrayList<FnBReservationEntity>();
        for (Object o : selectedReservations_confirm) {
            FnBReservationEntity temp = (FnBReservationEntity) o;

            reservationSessionBean.toRejected(temp.getId());
            temp.setConfirmation("Rejected");
            getFandBRejected().add(temp);

        }
        FacesContext.getCurrentInstance().getExternalContext().redirect("StakeholderViewConfirmationUpdateResult.xhtml");
    }

    public List<FnBReservationEntity> getFandBs() {
        return fandBs;
    }

    public void setFandBs(List<FnBReservationEntity> fandBs) {
        this.setFandBs(fandBs);
    }

    public List<FnBReservationEntity> getFandBShow() {
        return fandBShow;
    }

    public void setFandBShow(List<FnBReservationEntity> fandBShow) {
        this.fandBShow = fandBShow;
    }

    public List<FnBReservationEntity> getFandBNoShow() {
        return fandBNoShow;
    }

    public void setFandBNoShow(List<FnBReservationEntity> fandBNoShow) {
        this.fandBNoShow = fandBNoShow;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public void setAllFandB(List<FnBReservationEntity> allFandB) {
        this.allFandB = allFandB;
    }

    public FnBReservationEntity getSelectedReservation() {
        return selectedReservation;
    }

    public void setSelectedReservation(FnBReservationEntity selectedReservation) {
        this.selectedReservation = selectedReservation;
    }

    public String getOption() {
        return option;
    }

    public void setOption(String option) {
        this.option = option;
    }

    public List<String> getOptions() {
        return options;
    }

    public void setOptions(List<String> options) {
        this.options = options;
    }

    public List<FnBReservationEntity> getFandBConfirmed() {
        return fandBConfirmed;
    }

    public void setFandBConfirmed(List<FnBReservationEntity> fandBConfirmed) {
        this.fandBConfirmed = fandBConfirmed;
    }

    public List<FnBReservationEntity> getFandBRejected() {
        return fandBRejected;
    }

    public void setFandBRejected(List<FnBReservationEntity> fandBRejected) {
        this.setFandBRejected(fandBRejected);
    }

    public FnBReservationEntity[] getSelectedReservations_status() {
        return selectedReservations_status;
    }

    public void setSelectedReservations_status(FnBReservationEntity[] selectedReservations_status) {
        this.selectedReservations_status = selectedReservations_status;
    }

    public FnBReservationEntity[] getSelectedReservations_confirm() {
        return selectedReservations_confirm;
    }

    public void setSelectedReservations_confirm(FnBReservationEntity[] selectedReservations_confirm) {
        this.selectedReservations_confirm = selectedReservations_confirm;
    }

    public ReservationManagerBean() {
        listOfCategory = new ArrayList<List<FnBProductEntity>>();
        choiceList = new ArrayList<List<FnBProductEntity>>();
        reloadPage = true;
        foodMap = new HashMap<String, Integer>();
        priceList = new HashMap<Long, Double>();
        quantityList = new HashMap<Long, Integer>();
        reservation = new FnBReservationEntity();
        availSlot = new ArrayList();
    }

    //method for meal and set meal reservation
    public void init(PhaseEvent event) {
        if (reloadTable) {
            setListOfFoodType(productSessionBean.getFoodType());

            reloadTable = false;
        }
    }

    public void initProductList(PhaseEvent event) {
        if (reloadPage) {
            String temp = FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("branchId") + "";
            branchId = Long.parseLong(temp.trim());
            setListOfProduct(productSessionBean.getProductForReservation(branchId, reservation.getDateReserved()));
            System.out.println("SIZE is " + listOfProduct.size());
            numOfType = getListOfFoodType().size();
            selectedProduct = new FnBProductEntity[numOfType + 1];

            //Initialize for Meals
            for (int i = 0; i < numOfType; i++) {
                getListOfCategory().add(new ArrayList<FnBProductEntity>());
                choiceList.add(new ArrayList<FnBProductEntity>());
                foodMap.put(listOfFoodType.get(i).getName(), i);
            }

            //this one is for Set Meal
            choiceList.add(new ArrayList<FnBProductEntity>());
            getListOfCategory().add(new ArrayList<FnBProductEntity>());
            //no need to put the Set Meal into foodMap as it will always be in the last position

            //put the meal and set meal into their correct positions in listOfProduct
            for (int i = 0; i < getListOfProduct().size(); i++) {
                int pos = 0;
                if (getListOfProduct().get(i) instanceof MealEntity) {
                    MealEntity mealTemp = (MealEntity) getListOfProduct().get(i);
                    for (; pos < numOfType; pos++) {
                        FoodTypeEntity food1 = mealTemp.getType();
                        FoodTypeEntity food2 = getListOfFoodType().get(pos);
                        if (food1.equals(food2)) {
                            break;
                        }
                    }
                    getListOfCategory().get(pos).add(mealTemp);
                } else {
                    System.out.println("We get set meal here");
                    getListOfCategory().get(numOfType).add((SetMealEntity) getListOfProduct().get(i));
                }

                //finding price from price control
                priceList.put(listOfProduct.get(i).getId(), getOnlinePrice(listOfProduct.get(i).getId(),
                        reservation.getDateReserved(), reservation.getTimeBegin().getHours()));
            }
            //only load this method once
            reloadPage = false;
        }
    }

    private double getOnlinePrice(long productId, Date dateReserved, int time) {
        return productSessionBean.getOnlinePrice(productId, dateReserved, time);
    }

    public void onRowSelect(SelectEvent event) {
        meal = (FnBProductEntity) event.getObject();
        for (int i = 0; i < selectedProduct.length; i++) {
            if (selectedProduct[i] != null && !selectedProduct[i].equals(meal)) {
                selectedProduct[i] = null;
            }
        }
    }

    public void addToList(ActionEvent event) {
        if (meal != null) {
            if (quantity <= 0) {
                FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Quantity must be more than 0 ", "");
                FacesContext.getCurrentInstance().addMessage(null, msg);
                return;
            }

            int pos = findPosition(meal);
            choiceList.get(pos).add(meal);
            quantityList.put(meal.getId(), quantity);
            discountBill += priceList.get(meal.getId()) * quantityList.get(meal.getId());
            totalBill += meal.getOriginalPrice() * quantityList.get(meal.getId());

            FacesMessage msg = new FacesMessage("Added ", meal.getName());
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    }

    public void removeFromList(ActionEvent event) {
        if (meal != null) {
            int pos = findPosition(meal);
            choiceList.get(pos).remove(meal);
            discountBill -= priceList.get(meal.getId()) * quantityList.get(meal.getId());
            totalBill -= meal.getOriginalPrice() * quantityList.get(meal.getId());
            quantityList.remove(meal.getId());

            FacesMessage msg = new FacesMessage("Removed: ", meal.getName());
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    }

    public void changeValueInList(ActionEvent event) {
        if (meal != null) {
            int previousQuantity = quantityList.get(meal.getId());
            quantityList.remove(meal.getId());
            quantityList.put(meal.getId(), quantity);
            discountBill += priceList.get(meal.getId()) * (quantityList.get(meal.getId()) - previousQuantity);
            totalBill += meal.getOriginalPrice() * (quantityList.get(meal.getId()) - previousQuantity);

            FacesMessage msg = new FacesMessage("Changed quantity: ", meal.getName());
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    }

    private int findPosition(FnBProductEntity meal) {
        if (meal instanceof MealEntity) {
            return getPosition(((MealEntity) meal).getType().getName());
        }

        return numOfType;
    }

    public boolean checkContain() {
        if (meal != null) {
            int pos = findPosition(meal);
            if (choiceList.get(pos).contains(meal)) {
                return true;
            }
        }
        return false;
    }
    //end metho for meal and set meal reservation

    //methods for table reservation
    public void initTableList(ActionEvent event) throws IOException {
        finish = false;
        String temp = FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("branchId") + "";
        branchId = Long.parseLong(temp.trim());
        setTableList(reservationSessionBean.getTableList(branchId));

        capacity = new int[getTableList().size()][24][4];
        quantityAvail = new int[tableList.size()];
        testList = new ArrayList();
        selectedQuantity = new int[tableList.size()];
        boolean[][] avail = new boolean[24][4];

        for (int i = 0; i < getTableList().size(); i++) {
            capacity[i] = reservationSessionBean.getAvailTable(getTableList().get(i).getId(), getReservation().getDateReserved());
            printArray(capacity[i]);
        }

        for (int i = 0; i < 24; i++) {
            for (int j = 0; j < 4; j++) {
                int sum = 0;
                for (int k = 0; k < getTableList().size(); k++) {
                    sum += capacity[k][i][j] * getTableList().get(k).getUnitCapacity();
                }
                if (sum >= getReservation().getNoOfPeople()) {
                    avail[i][j] = true;
                }
            }
        }

        interval = reservationSessionBean.getIntervalByBranchId(branchId);

        generateAvailList(avail);

        printArray(avail);


    }

    private void printArray(int[][] arr) {
        for (int i = 0; i < arr[0].length; i++) {
            String temp = "";
            for (int j = 0; j < arr.length; j++) {
                temp += arr[j][i] + " ";
            }
            System.out.println(temp);
        }
    }

    private void printArray(boolean[][] arr) {
        for (int i = 0; i < arr[0].length; i++) {
            String temp = "";
            for (int j = 0; j < arr.length; j++) {
                temp += arr[j][i] + " ";
            }
            System.out.println(temp);
        }
    }

    private void generateAvailList(boolean[][] avail) {
        setAvailSlot(new ArrayList());
        int startHour = 0;
        int startMinute = 0;

        int endHour = 23;
        int endMinute = 3;

        int count = 0;

        while (startHour <= endHour && startMinute <= endMinute) {
            if (avail[startHour][startMinute]) {
                count++;
            } else {
                count = 0;
            }

            if (count >= interval) {
                int temp = startHour * 4 + startMinute - interval + 1;
                getAvailSlot().add(new SelectItem(temp, ((temp / 4) < 10 ? "0" : "") + temp / 4
                        + ":" + ((temp % 4) * 15) + (((temp % 4) * 15) == 0 ? "0" : "")));
            }

            startMinute++;
            if (startMinute == 4) {
                startMinute = 0;
                startHour++;
            }
        }

        if (availSlot.isEmpty()) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,
                    "Sorry we don't have enough capacity for this time", ""));
        }
    }

    public void chooseTableType(ActionEvent event) throws IOException {
        createTable = true;
        int hour = timeInput / 4;
        int minute = timeInput % 4;
        reservation.setTimeBegin(new Time(timeInput / 4, timeInput % 4 * 15, 0));
        reservation.setTimeEnd(new Time((timeInput + interval) / 4, (timeInput + interval) % 4 * 15, 0));
        for (int i = 0; i < getTableList().size(); i++) {
            int min = Integer.MAX_VALUE;

            for (int j = 0; j < interval; j++) {
                int temp = minute + j;
                if (min > capacity[i][hour + temp / 4][temp % 4]) {
                    min = capacity[i][hour + temp / 4][temp % 4];
                }
            }
            quantityAvail[i] = min;
        }
    }

    public void confirmTableTypeWithoutMeal(ActionEvent event) throws IOException {
        if (checkEnoughSeat()) {
            generateSelectedTableList();
            FacesContext.getCurrentInstance().getExternalContext().redirect("VisitorConfirmReservation.xhtml");
        }
    }

    public void confirmTableTypeWithMeal(ActionEvent event) throws IOException {
        if (checkEnoughSeat()) {
            generateSelectedTableList();
            FacesContext.getCurrentInstance().getExternalContext().redirect("VisitorSelectMeal.xhtml");
        }
    }

    private void generateSelectedTableList() {
        selectedTable = new ArrayList<TableTypeEntity>();
        selectedTableQuantity = new ArrayList<Integer>();
        for (int i = 0; i < tableList.size(); i++) {
            if (selectedQuantity[i] >= 0) {
                getSelectedTable().add(tableList.get(i));
                getSelectedTableQuantity().add(selectedQuantity[i]);
            }
        }
    }

    private boolean checkEnoughSeat() {
        int sum = 0;
        for (int i = 0; i < tableList.size(); i++) {
            if (selectedQuantity[i] <= quantityAvail[i]) {
                sum += selectedQuantity[i] * tableList.get(i).getUnitCapacity();
            } else {
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,
                        "You can't select more than maximum tables for table type " + tableList.get(i).getName(), ""));
                return false;
            }
        }

        if (sum < reservation.getNoOfPeople()) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,
                    "You only select " + sum + " seats while you have " + reservation.getNoOfPeople() + " people", ""));
            return false;
        }
        return true;
    }

    public String getReservedTime() {
        return ((timeInput / 4) < 10 ? "0" : "") + timeInput / 4
                + ":" + ((timeInput % 4) * 15) + (((timeInput % 4) * 15) == 0 ? "0" : "");
    }

    public String getReservedDate() {
        return reservation.getDateReserved().getDate() + "/" + (reservation.getDateReserved().getMonth() + 1)
                + "/" + (reservation.getDateReserved().getYear() + 1900);
    }

    //end method for table reservation
    public CustomerEntity getCustomer() {
        return customer;
    }

    public void setCustomer(CustomerEntity customer) {
        this.customer = customer;
    }

    public List<ProductEntity> getListOfProduct() {
        return listOfProduct;
    }

    public void setListOfProduct(List<ProductEntity> listOfProduct) {
        this.listOfProduct = listOfProduct;
    }

    public List<List<FnBProductEntity>> getListOfCategory() {
        return listOfCategory;
    }

    public void setListOfCategory(List<List<FnBProductEntity>> listOfCategory) {
        this.setListOfCategory(listOfCategory);
    }

    public List<FoodTypeEntity> getListOfFoodType() {
        return listOfFoodType;
    }

    public void setListOfFoodType(List<FoodTypeEntity> listOfFoodType) {
        this.listOfFoodType = listOfFoodType;
    }

    public FnBProductEntity[] getSelectedProduct() {
        return selectedProduct;
    }

    public void setSelectedProduct(FnBProductEntity[] selectedProduct) {
        this.selectedProduct = selectedProduct;
    }

    public List<List<FnBProductEntity>> getChoiceList() {
        return choiceList;
    }

    public void setChoiceList(List<List<FnBProductEntity>> choiceList) {
        this.choiceList = choiceList;
    }

    public int getPosition(String name) {
        return foodMap.get(name);
    }

    public double getPrice() {
        if (meal != null) {
            return priceList.get(meal.getId());
        }
        return 0;
    }

    public double getPrice1(long id) {
        System.out.println(id);
        return priceList.get(id);
    }

    public int getSpecificQuantity(long id) {
        return quantityList.get(id);
    }

    public FnBProductEntity getMeal() {
        if (meal != null) {
            return meal;
        }

        return new MealEntity();
    }

    public void makeReservation(ActionEvent event) {
        setCustomer((CustomerEntity) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("customer"));
        String result = reservationSessionBean.addReservation(reservation, customer.getId(), branchId, choiceList,
                priceList, quantityList, selectedTable, selectedTableQuantity);
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,
                result, ""));
        finish = true;
    }

    public void finishReservation(ActionEvent event) throws IOException {
        FacesContext.getCurrentInstance().getExternalContext().redirect("VisitorLogin.xhtml");
    }

    public void setMeal(MealEntity meal) {
        this.meal = meal;
    }

    public Map<Long, Integer> getQuantityList() {
        return quantityList;
    }

    public void setQuantityList(Map<Long, Integer> quantityList) {
        this.quantityList = quantityList;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public double getTotalBill() {
        return totalBill;
    }

    public void setTotalBill(double totalBill) {
        this.totalBill = totalBill;
    }

    public double getDiscountBill() {
        return discountBill;
    }

    public void setDiscountBill(double discountBill) {
        this.discountBill = discountBill;
    }

    public FnBReservationEntity getReservation() {
        return reservation;
    }

    public void setReservation(FnBReservationEntity reservation) {
        this.reservation = reservation;
    }

    public List getAvailSlot() {
        return availSlot;
    }

    public void setAvailSlot(List availSlot) {
        this.availSlot = availSlot;
    }

    public int getTest() {
        return test;
    }

    public void setTest(int test) {
        this.test = test;
    }

    public List<TableTypeEntity> getTableList() {
        return tableList;
    }

    public void setTableList(List<TableTypeEntity> tableList) {
        this.tableList = tableList;
    }

    public int[] getSelectedQuantity() {
        return selectedQuantity;
    }

    public void setSelectedQuantity(int[] selectedQuantity) {
        this.selectedQuantity = selectedQuantity;
    }

    public int getQuantityAvail() {

        int tempNum = quantityAvail[count2];
        count2 = (count2 + 1) % tableList.size();
        return tempNum;
        //return quantityAvail;
    }

    public void setQuantityAvail(int[] quantityAvail) {
        this.quantityAvail = quantityAvail;
    }

    public List getTestList() {
        return testList;
    }

    public void setTestList(List testList) {
        this.testList = testList;
    }

    public Integer getTestClass() {
        return testClass;
    }

    public void setTestClass(Integer testClass) {
        this.testClass = testClass;
    }

    public int getIndex() {
        index = selectedQuantity[count1];
        count1 = (count1 + 1) % tableList.size();
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
        selectedQuantity[count] = index;
        count = (count + 1) % tableList.size();
    }

    public List<TableTypeEntity> getSelectedTable() {
        return selectedTable;
    }

    public void setSelectedTable(List<TableTypeEntity> selectedTable) {
        this.selectedTable = selectedTable;
    }

    public List<Integer> getSelectedTableQuantity() {
        return selectedTableQuantity;
    }

    public void setSelectedTableQuantity(List<Integer> selectedTableQuantity) {
        this.selectedTableQuantity = selectedTableQuantity;
    }

    public int getTimeInput() {
        return timeInput;
    }

    public void setTimeInput(int timeInput) {
        this.timeInput = timeInput;
    }

    public boolean isFinish() {
        return finish;
    }

    public void setFinish(boolean finish) {
        this.finish = finish;
    }

    public boolean isCreateTable() {
        return createTable;
    }

    public void setCreateTable(boolean createTable) {
        this.createTable = createTable;
    }
}
